define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'article/index' + location.search,
                    add_url: 'article/add',
                    edit_url: 'article/edit',
                    del_url: 'article/del',
                    multi_url: 'article/multi',
                    import_url: 'article/import',
                    table: 'article',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'article_id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'article_id', title: __('Article_id')},
                        {field: 'category.name', title: __('Category.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'content', title: __('Content')},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {
                            field: 'operate', title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons:[

                                {
                                    name: 'recommend',
                                    text: __('推荐'),
                                    confirm:'确认推荐吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'article/recommend',
                                    visible:function(row){
                                        if(row.is_recommend == 0){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'cancel_recommend',
                                    text: __('取消推荐'),
                                    confirm:'确认取消推荐吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'article/cancelrecommend',
                                    visible:function(row){
                                        if(row.is_recommend == 1){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'settop',
                                    text: __('置顶'),
                                    confirm:'确认置顶吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'article/settop',
                                    visible:function(row){
                                        if(row.is_top == 0){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name: 'cancel_top',
                                    text: __('取消置顶'),
                                    confirm:'确认取消置顶吗?',
                                    icon: '',
                                    refresh:true,
                                    classname: 'btn btn-info btn-xs btn-detail  btn-ajax',
                                    url: 'article/canceltop',
                                    visible:function(row){
                                        if(row.is_top == 1){
                                            return true;
                                        }
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
             //UE.getEditor("c-content");

            Controller.api.bindevent();
        },
        edit: function () {
            /*UE.getEditor("c-content");
            require(['ZeroClipboard'], function (ZeroClipboard) {
                window['ZeroClipboard'] = ZeroClipboard;
            });*/

            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
